home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / MorphOS / cvs-1.11.2 / source / amiga / netinclude / sys / mbuf.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-18  |  5.6 KB  |  158 lines

  1. /*
  2.  * Copyright (c) 1982, 1986, 1988, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)mbuf.h    8.5 (Berkeley) 2/19/95
  34.  */
  35.  
  36. #ifndef _SYS_MBUF_H
  37. #define _SYS_MBUF_H
  38.  
  39. #ifndef EXEC_TYPES_H
  40. #include <exec/types.h>
  41. #endif /* EXEC_TYPES_H */
  42.  
  43. #ifndef _NET_IF_H
  44. #include <net/if.h>
  45. #endif /* _NET_IF_H */
  46.  
  47. /*
  48.  * Constants related to network buffer management.
  49.  * MCLBYTES must be no larger than CLBYTES (the software page size), and,
  50.  * on machines that exchange pages of input or output buffers with mbuf
  51.  * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
  52.  * of the hardware page size.
  53.  */
  54. #define    MSIZE        128        /* size of an mbuf */
  55. #define    MCLBYTES    2048        /* large enough for ether MTU */
  56. #define    MCLSHIFT    11
  57. #define    MCLOFSET    (MCLBYTES - 1)
  58.  
  59. /*
  60.  * Mbufs are of a single size, MSIZE (machine/machparam.h), which
  61.  * includes overhead.  An mbuf may add a single "mbuf cluster" of size
  62.  * MCLBYTES (also in machine/machparam.h), which has no additional overhead
  63.  * and is used instead of the internal data area; this is done when
  64.  * at least MINCLSIZE of data must be stored.
  65.  */
  66.  
  67. #define    MLEN        (MSIZE - sizeof(struct m_hdr))    /* normal data len */
  68. #define    MHLEN        (MLEN - sizeof(struct pkthdr))    /* data len w/pkthdr */
  69.  
  70. #define    MINCLSIZE    (MHLEN + MLEN)    /* smallest amount to put in cluster */
  71. #define    M_MAXCOMPRESS    (MHLEN / 2)    /* max amount to copy for compression */
  72.  
  73. /*
  74.  * Macros for type conversion
  75.  * mtod(m,t) -    convert mbuf pointer to data pointer of correct type
  76.  * dtom(x) -    convert data pointer within mbuf to mbuf pointer (XXX)
  77.  */
  78. #define    mtod(m,t)    ((t)((m)->m_data))
  79. #define    dtom(x)        ((struct mbuf *)((long)(x) & ~(MSIZE-1)))
  80.  
  81. /* header at beginning of each mbuf: */
  82. struct m_hdr {
  83.     struct    mbuf *mh_next;        /* next buffer in chain */
  84.     struct    mbuf *mh_nextpkt;    /* next chain in queue/record */
  85.     APTR    mh_data;        /* location of data */
  86.     LONG    mh_len;            /* amount of data in this mbuf */
  87.     WORD    mh_type;        /* type of data in this mbuf */
  88.     WORD    mh_flags;        /* flags; see below */
  89. };
  90.  
  91. /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
  92. struct    pkthdr {
  93.     struct    ifnet *rcvif;        /* rcv interface */
  94.     LONG    len;            /* total packet length */
  95. };
  96.  
  97. /* description of external storage mapped into mbuf, valid if M_EXT set */
  98. struct m_ext {
  99.     APTR    ext_buf;        /* start of buffer */
  100.     APTR    ext_free;        /* free routine if not the usual */
  101.     ULONG    ext_size;        /* size of buffer, for ext_free */
  102. };
  103.  
  104. struct mbuf {
  105.     struct    m_hdr m_hdr;
  106.     union {
  107.         struct {
  108.             struct    pkthdr MH_pkthdr;    /* M_PKTHDR set */
  109.             union {
  110.                 struct    m_ext MH_ext;    /* M_EXT set */
  111.                 UBYTE    MH_databuf[MHLEN];
  112.             } MH_dat;
  113.         } MH;
  114.         UBYTE    M_databuf[MLEN];        /* !M_PKTHDR, !M_EXT */
  115.     } M_dat;
  116. };
  117. #define    m_next        m_hdr.mh_next
  118. #define    m_len        m_hdr.mh_len
  119. #define    m_data        m_hdr.mh_data
  120. #define    m_type        m_hdr.mh_type
  121. #define    m_flags        m_hdr.mh_flags
  122. #define    m_nextpkt    m_hdr.mh_nextpkt
  123. #define    m_act        m_nextpkt
  124. #define    m_pkthdr    M_dat.MH.MH_pkthdr
  125. #define    m_ext        M_dat.MH.MH_dat.MH_ext
  126. #define    m_pktdat    M_dat.MH.MH_dat.MH_databuf
  127. #define    m_dat        M_dat.M_databuf
  128.  
  129. /* mbuf flags */
  130. #define    M_EXT        0x0001    /* has associated external storage */
  131. #define    M_PKTHDR    0x0002    /* start of record */
  132. #define    M_EOR        0x0004    /* end of record */
  133.  
  134. /* mbuf pkthdr flags, also in m_flags */
  135. #define    M_BCAST        0x0100    /* send/received as link-level broadcast */
  136. #define    M_MCAST        0x0200    /* send/received as link-level multicast */
  137.  
  138. /* flags copied when copying m_pkthdr */
  139. #define    M_COPYFLAGS    (M_PKTHDR|M_EOR|M_BCAST|M_MCAST)
  140.  
  141. /* length to m_copy to copy all */
  142. #define    M_COPYALL    1000000000
  143.  
  144. /*
  145.  * Mbuf statistics.
  146.  */
  147. struct mbstat {
  148.     ULONG    m_mbufs;    /* mbufs obtained from page pool */
  149.     ULONG    m_clusters;    /* clusters obtained from page pool */
  150.     ULONG    m_spare;    /* spare field */
  151.     ULONG    m_clfree;    /* free clusters */
  152.     ULONG    m_drops;    /* times failed to find space */
  153.     ULONG    m_wait;        /* times waited for space */
  154.     ULONG    m_drain;    /* times drained protocols for space */
  155. };
  156.  
  157. #endif /* _SYS_MBUF_H */
  158.